package com.abc.service.impl;

import com.abc.api.SiliconflowApi;
import com.abc.dto.request.RerankRequestDto;
import com.abc.dto.response.RerankResponseDto;
import com.abc.service.RerankService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 重排序服务实现类
 */
@Slf4j
@Service
public class RerankServiceImpl implements RerankService {

    @Autowired
    private SiliconflowApi siliconflowApi;

    @Override
    public RerankResponseDto rerank(@Valid RerankRequestDto requestDto) {
        log.info("执行文档重排序，查询: {}, 文档数: {}", 
                requestDto.getQuery(), requestDto.getDocuments().size());
        
        try {
            RerankResponseDto response = siliconflowApi.rerank(requestDto);
            log.info("文档重排序完成，返回 {} 个结果", 
                    response.getResults() != null ? response.getResults().size() : 0);
            return response;
        } catch (Exception error) {
            log.error("文档重排序失败", error);
            throw error;
        }
    }
}
